package com.common.util;

import java.lang.reflect.Type;
import java.util.HashMap;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;


/**
 * 
 * @author caolini
 *
 */
public class JsonToObject {

	/**
	 * json to map
	 * 
	 * @param json
	 */
	public static HashMap<Object, Object> jsonToJavaMap(String json) {

		Gson gson2 = new GsonBuilder().enableComplexMapKeySerialization().create();
		Type type = new TypeToken<HashMap<Object, Object>>() {}.getType();
		HashMap<Object, Object> paramMap = gson2.fromJson(json, type);
		return paramMap;

	}
	
	public static final String toJSONString(Object object) {
		Gson gson2 = new Gson();
        return gson2.toJson(object);
    }


}
